import java.util.ArrayList;


public class RushHourHeuristic1 implements Heuristic {
	
	public void init(State initialState) {
		
	}
	
    // NOTE: This heuristic function assumes that car0 lies horizontally on the grid and that the exit goal is on the right-hand side of car0.
    //       The test-bed itself does not make these constraints, e.g. the exit can be on any of the four sides of the grid and car0 can both be
    //       placed horizontally and vertically.. but it's up to you to choose :) hehe options == nothing but a pain in the a**.
	public int getHeuristic(State state) {
        // YEEEEESSS... so for starters you get this heuristic function:
        //  Counts how many cars are blocking the exit
        //  Believe me this heuristic function s*cks.. highly recommend that you use your newfound heuristic-intuition to make a better one :D

		callCounter++;
		RushHourState s = (RushHourState)state;
        RushHourCar car0 = s.cars.get(0);
        int upper_limit = s.grid.getWidth(); // Get the right-hand side of the grid
        int count = 0; // Yeah.. mkay a counter ok!

        // Create the merged grid.. this is rather expensive to do in a heuristic function which is called repeatedly,
        // you might want to do this differently (hint, hint) :)
        RushHourGrid tgrid = s.grid.merge( s.cars );

        for( int i=car0.getHead().getCol()+car0.getLength(); i<upper_limit;++i)
        {
            if( !tgrid.isFree(i,car0.getHead().getRow()) )
                count++;
        }
    
        return count;		
	}
	
	public long callCounter = 0;
	public long getCallCount(){return callCounter;}	
}
